package com.cloud.tsp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.api.annotation.TransUser;
import com.cloud.api.domain.tsp.CommandLog;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.mapper.CommandLogMapper;
import com.cloud.tsp.service.ICommandLogService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-26
 */
@Service("commandLogService")
public class CommandLogServiceImpl extends ServiceImpl<CommandLogMapper, CommandLog> implements ICommandLogService {

    @Resource
    private CommandLogMapper commandLogMapper;

    @Override
    @TransUser
    public TableDataInfo<CommandLog> selectCommandLog(String modelId) {
        List<CommandLog> commandLogs = commandLogMapper.selectCommandLog(modelId);
        commandLogs.forEach(a -> {
            if ("变更指令".equals(a.getOperateType())){
                a.setContent("\"" + a.getCommandName() + "\"" +"由" + (a.getOldStatus() == 0 ? "未勾选" : "已勾选") +"变更为"+ (a.getNewStatus() == 0 ? "未勾选" : "已勾选"));
            }else {
                a.setContent(a.getCommandName());
            }
        });
        return TableDataInfo.build(commandLogs);
    }
}